package com.hazardSoft.eStore.entities;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Transient;

import com.hazardSoft.eStore.utils.QueryConstants;

@Entity
@NamedQueries({
	@NamedQuery(name = QueryConstants.QUERY_LIST_CITIES, query = "FROM City c ORDER BY c.name ASC"),
	@NamedQuery(name = QueryConstants.QUERY_LIST_CITIES_BY_DEPARTMENT, query = "FROM City ci WHERE ci.department=?1 ORDER BY ci.name ASC")
})
public class City implements Serializable {
	@Id
	private int id;

	@Lob
	private String name;

	@ManyToOne
	@JoinColumn(name="department")
	private Department department;

//	@OneToMany(mappedBy="city")
//	private Set<User> userCollection;

//	@ManyToMany(mappedBy="cityCollection")
	@Transient
	private Collection<Office> officeCollection;

	private static final long serialVersionUID = 1L;

	public City() {
		super();
	}

	public City(int id) {
		this.id = id;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Department getDepartment() {
		return this.department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

//	public Collection<User> getUserCollection() {
//		return this.userCollection;
//	}
//
//	public void setUserCollection(Collection<User> userCollection) {
//		this.userCollection = userCollection;
//	}

	public Collection<Office> getOfficeCollection() {
		return this.officeCollection;
	}

	public void setOfficeCollection(Collection<Office> officeCollection) {
		this.officeCollection = officeCollection;
	}
	
	public String toString(){
		StringBuffer cityString = new StringBuffer();
		
		cityString.append("id: ["+this.getId()+"] ");
		cityString.append("name: ["+this.getName()+"] ");
		cityString.append("department: ["+this.getDepartment()+"] ");
		
		return cityString.toString();
	}
}
